#include <Arduino.h>
#include "oled.h"
#include "bmp.h"

u8 ref=0;//刷新显示
u16 vx=15542,vy=11165;  //比例因子，此值除以1000之后表示多少个AD值代表一个像素点
u16 chx=140,chy=146;//默认像素点坐标为0时的AD起始值
void xianshi()//显示信息
{   
  u16 lx,ly;
  OLED_BACK_COLOR=WHITE;
  OLED_POINT_COLOR=RED;  
  showhanzi(10,0,0);  //中
  showhanzi(45,0,1);  //景
  showhanzi(80,0,2);  //园
  showhanzi(115,0,3);  //电
  showhanzi(150,0,4);  //子
  OLED_ShowString(10,35,(const unsigned char *)"2.4 TFT SPI 240*320");
  OLED_ShowString(10,55,(const unsigned char *)"LCD_W:");  OLED_ShowNum(70,55,OLED_W,3);
  OLED_ShowString(110,55,(const unsigned char *)"LCD_H:");OLED_ShowNum(160,55,OLED_H,3); 
  lx=10;ly=75;      
}



void showimage() //显示40*40图片
{
    int i,j,k; 

  for(k=2;k<6;k++)
  {
      for(j=0;j<6;j++)
    { 
      Address_set(40*j,40*k,40*j+39,40*k+39);   //坐标设置
        for(i=0;i<1600;i++)
       {  
            
           OLED_WR_DATA8(image[i*2+1]);   
         OLED_WR_DATA8(image[i*2]);        
       }  
     }
  }
  ref=0;        
}

extern "C" void test() {
  int size = esp_get_free_heap_size();
  Serial.printf("size == %d\r\n", size);
  size = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
  Serial.printf("size == %d\r\n", size);
}

extern "C" void test2(long t) {
  Serial.printf("time == %d \r\n", millis() - t);     
}

extern "C" void test3(long t) {
  Serial.printf("lasttime == %d \r\n", millis() - t);     
}

void setup() {
    Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  // put your setup code here, to run once:
   OLED_Init();      //初始化OLED  
   OLED_Init(); 
  
  OLED_Clear(WHITE); //清屏
  OLED_BACK_COLOR=BLACK;OLED_POINT_COLOR=WHITE; 

  xianshi(); //显示信息
    showimage(); //显示40*40图片
}

extern "C" int InfoNES_main_entry(void);

void loop() {
  // put your main code here, to run repeatedly:
  /*
  digitalWrite(LED_BUILTIN, HIGH);   
  delay(2000);                       
  digitalWrite(LED_BUILTIN, LOW);    
  delay(2000);*/
  OLED_Clear(BLACK);
  OLED_BACK_COLOR=BLACK;OLED_POINT_COLOR=WHITE; 
  digitalWrite(LED_BUILTIN, HIGH);   
  delay(2000);                       
  digitalWrite(LED_BUILTIN, LOW);    
  delay(2000);
  
  InfoNES_main_entry();
}
